package tk.xboot.boot.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tk.xboot.boot.event.CustomEvent;
import tk.xboot.boot.event.EventBean;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("event")
public class EventController {
    @Resource
    private ApplicationEventPublisher eventPublisher;


    @GetMapping
    public String push(String code,String message) {
        log.info("发布applicationEvent事件:{},{}", code, message);
        eventPublisher.publishEvent(new CustomEvent(this, new EventBean(code,message)));
        return "事件发布成功!";
    }

    @GetMapping("/obj")
    public String pushObject(String code,String message) {
        log.info("发布对象事件:{},{}", code, message);
        eventPublisher.publishEvent(new EventBean(code,message));
        return "对象事件发布成功!";
    }

}
